//#condition PimFile
//# package MicroLogos;
//# 
//# /*
//#  * pimFile.java
//#  *
//#  * Created on 2. �nor 2007, 17:44
//#  *
//#  * To change this template, choose Tools | Template Manager
//#  * and open the template in the editor.
//#  */
//# 
//# import javax.microedition.midlet.*;
//# import java.io.*;
//# import javax.microedition.io.*;
//# import javax.microedition.io.file.*;
//# 
//# /**
//#  *
//#  * @author Marek
//#  */
//# public class PimFile extends com.siemens.mp.io.File{
//#   public static int NUM_HANDLES=20;
//#   public static int READ=0;
//#   public static int WRITE=1;
//#   public static int READ_WRITE=2;
//# //  public static int BLOCK_SIZE=4096; 
//# 
//#   public PimFile() {
//#     fileConnections=new FileConnection[NUM_HANDLES];
//#     inputStreams=new InputStream[NUM_HANDLES];
//#     pozitions=new int[NUM_HANDLES];
//#     blockSizes=new int[NUM_HANDLES];
//# //    firstSeeks=new int[NUM_HANDLES];
//#     for (int i=0;i<NUM_HANDLES;i++) inputStreams[i]=null;
//#   }
//#   FileConnection fileConnections[];
//#  InputStream[] inputStreams;
//#  int []pozitions;
//#  int[] blockSizes;
//# // int []firstSeeks;
//# // int number=0;
//#  public int length(int fd) {
//# //   if (inputStreams[fd]==null) return -1;
//#  if (fd<0||fd>=NUM_HANDLES) {System.out.println("Nemelo by se stat: fd ven z mezi");return -1;}
//#    try{
//#      if (fileConnections[fd].isDirectory()){
//# System.out.println("PIM-length - pripad directory "+fileConnections[fd].getURL()+"size");
//# //       return (int) fileConnections[fd].directorySize(false);
//#         InputStream is=Connector.openInputStream(fileConnections[fd].getURL()+"size");
//# System.out.println("PIM-length - po open \".../size\"");
//#         byte[]b=new byte[4];
//#         is.read(b);
//#         is.close();
//# System.out.println("b[0]"+b[0]+"b[1]"+b[1]+"b[2]"+b[2]+"b[3]"+b[3]);
//#         return (b[0]|(b[1]<<8)|(b[2]<<16)|b[3]<<24);
//#      }
//#      else return (int) fileConnections[fd].fileSize();//ani neni korektni
//#    }catch (IOException e) {System.out.println("IO v PimFile.length():"+e.toString());
//#    e.printStackTrace();
//#    return -1;}
//#  }
//#  public int open(String fileName,int mode) throws IOException{
//#    return open(fileName);
//#  }
//#  public int open(String fileName) throws IOException{
//#    int i=0;
//#    for (i=0;i<NUM_HANDLES;i++) if (fileConnections[i]==null) break;
//#    if (i==NUM_HANDLES) {return -1;}
//#    FileConnection fc=null;
//#    try{
//#      fc=(FileConnection)Connector.open(fileName,Connector.READ);
//#      if (!fc.exists()) throw new IOException("Soubor neexistuje");//fc.create();
//#      fileConnections[i]=fc;
//# //     inputStreams[i]=fc.openInputStream();
//# //     inputStreams[i].mark(Integer.MAX_VALUE);
//# //     firstSeeks[i]=0;
//#      pozitions[i]=Integer.MAX_VALUE;
//#      if (fc.isDirectory()){
//#        FileConnection fcon=(FileConnection)Connector.open(
//#                fc.getURL()+"0",Connector.READ_WRITE);
//#        int avail=(int)fcon.fileSize();
//# System.out.println("fileSize pro BS vraci "+avail);
//#        blockSizes[i]=avail;
//#        fcon.close();
//#      }//else blockSizes[i]=1;//!!nemelo by byt potreba, ale debilni java?
//#    }catch (Exception e) {
//#      System.out.println("PimOpen(): "+e.toString());
//#      fc.close();
//#      return -1; 
//#    }
//#    return i;
//#  }
//#  public int write(int fd,byte[]buf, int offset, int numbytes)throws IOException{
//# //     FileConnection fileCon=(FileConnection)Connector.open("file://"+fileNames[fd],Connector.READ_WRITE);
//#      int i=fd;
//#      if (!fileConnections[i].exists()) fileConnections[i].create();
//#      OutputStream os=fileConnections[i].openOutputStream(pozitions[i]);
//#      os.write(buf, offset, numbytes);
//#      os.close();
//#      return numbytes;
//#  }
//#  public int read(int fd, byte[] buf, int offset, int numBytes)throws IOException{
//# if (fd<0||fd>=NUM_HANDLES) {System.out.println("Nemelo by se stat: fd ven z mezi");return 0;}
//# if (offset<0||offset+numBytes>buf.length) {System.out.println("Nemelo by se stat: offset ven z mezi bufu "+offset+" "+numBytes);return 0;}
//#    if (inputStreams[fd]==null) seek(fd,0);
//# //   try{
//#    int read=0;
//#    int readOnce;
//#    if (fileConnections[fd].isDirectory()) do{
//#      readOnce= inputStreams[fd].read(buf,offset,numBytes);
//#      read+=readOnce;
//#      offset+=readOnce;
//#      numBytes-=readOnce;
//#      if ((pozitions[fd]+readOnce)%blockSizes[fd]==0) 
//#        seek(fd,pozitions[fd]+readOnce);
//#      else pozitions[fd]+=readOnce;
//#    }while (readOnce>0&&numBytes>0);
//#    else {
//#      read= inputStreams[fd].read(buf,offset,numBytes);
//#      if (read==-1) read=0;
//#      pozitions[fd]+=read;
//#    }
//#    return read;
//# //   }catch (IOException e) {return -1;}
//#  }
//#  public int seek(int fd, int seekpos)throws IOException{
//# //System.out.println("zac seek");
//# if (fd<0||fd>=NUM_HANDLES) {System.out.println("Nemelo by se stat: fd ven z mezi");return -1;}
//#    if (fileConnections[fd]==null) throw new IOException("seek: soubor "+fd+" nebyl otevren");
//# //   try{
//#      if (pozitions[fd]>seekpos||inputStreams[fd]==null||
//#        (fileConnections[fd].isDirectory()&&(seekpos/blockSizes[fd]!=
//#         pozitions[fd]/blockSizes[fd]))) {
//#        if (inputStreams[fd]!=null) inputStreams[fd].close();
//#        if (fileConnections[fd].isDirectory()){
//#          inputStreams[fd]=Connector.openInputStream(fileConnections[fd].getURL()+
//#            seekpos/blockSizes[fd]);
//#          pozitions[fd]=(seekpos/blockSizes[fd])*blockSizes[fd];
//#        }else{
//#          inputStreams[fd]=fileConnections[fd].openInputStream();//.reset();
//#          pozitions[fd]=0;
//#        }
//# //System.out.println("znovuotevreni");
//#      }
//# //System.out.println("pred skip");
//#      inputStreams[fd].skip(seekpos-pozitions[fd]);
//# //System.out.println("po skip");
//#      pozitions[fd]=seekpos;
//# /*     if (firstSeeks[fd]==0){//ve slovniku nikdy necteme hlavicku dvakrat
//#        inputStreams[fd].mark(Integer.MAX_VALUE);
//#        firstSeeks[fd]=seekpos;
//#      }*/
//#      return seekpos;
//# //   }catch (IOException e) {return -1;}
//#  }
//#  public int close(int fd) throws IOException{
//#  if (fd<0||fd>=NUM_HANDLES) {System.out.println("Nemelo by se stat: fd ven z mezi");return -1;}
//#  if (fileConnections[fd]==null)return -1;
//#    int ret=1;
//#    try{
//#       if (inputStreams[fd]!=null) inputStreams[fd].close();
//#       fileConnections[fd].close();
//#    }catch(IOException e){ret=-1;}
//# //   finally{
//#      fileConnections[fd]=null;
//# //   }
//#    return ret;
//#  }
//#  
//#  public int existsNonStatic(String filename){
//#    int ret=-1;
//#    FileConnection fc=null;
//#    try{
//#      fc=(FileConnection) Connector.open(filename);
//#      if (fc.exists()) ret=1;
//#    }catch (IOException e) {ret=-1;}
//#    if (fc!=null) {try{fc.close();}catch(IOException e){}}
//#    return ret;
//#  }
//#   
//# 
//# }
//# 